using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using RomanJendrusz.Amazon.ETL.Infrastructure.DataBase;
namespace AmazonTests.Utils
{
    public class ListQuerySource<T>: IQuerySource<T> 
    {
        private readonly List<T> list;
        private readonly IQueryable<T> queryble;

        public ListQuerySource(params T[] items)
        {
            list = new List<T>(items);
            queryble =list.AsQueryable();
        }

        public ListQuerySource(List<T> list)
        {
            this.list = list;
            queryble = list.AsQueryable();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<T>) this).GetEnumerator();
        }

        public IEnumerator<T> GetEnumerator()
        {
            return list.GetEnumerator();
        }

        public Expression Expression
        {
            get { return queryble.Expression; }
        }

        public Type ElementType
        {
            get { return queryble.ElementType; }
        }

        public IQueryProvider Provider
        {
            get { return queryble.Provider; }
        }

        public void Add(T item)
        {
            list.Add(item);
        }

        public void Attach(T item)
        {
            list.Add(item);
        }

        public void Remove(T item)
        {
            list.Remove(item);
        }

        public void RemoveAll(IEnumerable<T> items)
        {
            foreach (var item in items)
            {
                list.Remove(item);
            }
        }

        public void AddAll(IEnumerable<T> items)
        {
            list.AddRange(items);
        }
    }
}